﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace SQLDataUploadHelper.models.domain
{
    /// <summary>
    /// 数据库连接配置信息
    /// </summary>
    public class SqlConnectConfig : INotifyPropertyChanged
    {
        private long idProperty = -1;
        private string ipProperty = "127.0.0.1";
        private string databaseNameProperty = "";
        private string userNameProperty = "";
        private string passwordProperty = "";

        public long Id
        {
            get { return idProperty; }
            set
            {
                idProperty = value;
                NotifyPropertyChanged("Id");
            }
        }

        public string Ip
        {
            get { return ipProperty; }
            set
            {
                ipProperty = value;
                NotifyPropertyChanged("Ip");
            }
        }

        public string DatabaseName
        {
            get { return databaseNameProperty; }
            set
            {
                databaseNameProperty = value;
                NotifyPropertyChanged("DatabaseName");
            }
        }

        public string UserName
        {
            get { return userNameProperty; }
            set
            {
                userNameProperty = value;
                NotifyPropertyChanged("UserName");
            }
        }

        public string Password
        {
            get { return passwordProperty; }
            set
            {
                passwordProperty = value;
                NotifyPropertyChanged("Password");
            }
        }

        /// <summary>
        /// 获取连接指令
        /// </summary>
        /// <returns></returns>
        public string getConnectCommond()
        {
            return string.Format("Data Source={0};User id={1};Password={2};Database={3}",
                ipProperty, userNameProperty, passwordProperty, databaseNameProperty);
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
